home *** CD-ROM | disk | FTP | other *** search
- Path: s02.pavilion.co.uk!usenet
- From: AJRobb@pavilion.co.uk (Andy J Robb)
- Newsgroups: comp.lang.c
- Subject: Re: f;oating point precision
- Date: Thu, 07 Mar 1996 05:45:18 GMT
- Organization: Pavilion Internet plc
- Message-ID: <4hlt40$au@s02.pavilion.co.uk>
- References: <c0d_9603050128@csource.blaze.net.au>
- NNTP-Posting-Host: poolc15.pavilion.co.uk
- X-Newsreader: Forte Free Agent 1.0.82
-
- David.Burrows@f158.n633.z3.fidonet.org (David Burrows) wrote:
-
- >Help.... I am getting floating point innaccuracies at about the 4th decimal
-
- >place. eg i enter 510.0250 and it comes out as 510.0249.
- >I am just starting to learn c so please excuse my ignorance.
- > dave
-
- -----BEGIN PGP SIGNED MESSAGE-----
-
- Hi Dave,
- In general, a (float) number will only be accurate to 5 or 6
- significant figures. In your example, the innacuracy occured in the
- 6th digit. If you used "%8.3f" to display the number, you should see
- "510.025". BTW, if you display 7 significant figures, you have enough
- information to recreate the exact binary image of the number when you
- scan it back in (assuming IEEE P795 floating point binary format).
-
- A (double) will generally be accurate to 14 significant figures. This
- does not mean that you can represent 510.025 exactly - in binary you
- can't. However, the error will be small. Again, to store the full
- precision of a (double) requires a 17 digit mantissa.
-
- As you are just starting, may I suggest that you obtain a copy of the
- frequently asked questions (FAQ). This gets posted about once a month
- to this newsgroup, so it may still be on your news feed. It seems it
- was last posted on 1-Feb-1996. Alternatively, if you have a web
- brouser, go to URL:
-
- http://www.eskimo.com/~scs/C-faq.top.html
-
- Regards,
- Andy Robb.
-
-
- -----BEGIN PGP SIGNATURE-----
- Version: 2.6.2i
-
- iQCVAwUBMT53y5Pl4P16x9sNAQHAFgP9FATdVBX4BbDHgybM9D9WvGbNacxxbZne
- rl1UOgsiGk0aOALbDWQuGW8+OgtE1gAYv144W5ObNOkO1zJQTt0KTfvDSQ35c+91
- FbObvYc1DZcALe9kHv+BsHkZhFXpWO4xPNTfYbLSnF+JlNrHxuENzc4E42y7+4MP
- BWjkEDg+ZTE=
- =t/AV
- -----END PGP SIGNATURE-----
-
- -----BEGIN PGP PUBLIC KEY BLOCK-----
- Version: 2.6.2i
-
- mQCNAy/MpRwAAAEEAOt6uBYqT8yv9EmqNhK8m6v+bYi8QjnGW3Bo6iU1gsMj5pa6
- MHgq99c8deADbE3cbJ6uZS9v5pZE3WCf6HCQjlB5iULA5RZzMdAumd/WUzuL9UT3
- B44D9EqqFIL79FlYb56v4oKFqFp1/J2bIpYUwnUvabGzGjdLrpPl4P16x9sNAAUR
- tCNBbmR5IEogUm9iYiA8QUpSb2JiQHBhdmlsaW9uLmNvLnVrPrQhQW5keSBSb2Ji
- IDxBSlJvYmJAcGF2aWxpb24uY28udWs+
- =/wVD
- -----END PGP PUBLIC KEY BLOCK-----
-
-